package com.pipe.servicepipe.entity.bo;

import com.pipe.servicepipe.entity.PipeUser;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.Arrays;
import java.util.Collection;

/**
 * @ClassName AdminUserDetails
 * @Author HETAO
 * @Date 2020/7/19 17:03
 */
public class AdminUserDetails implements UserDetails {
    private PipeUser pipeUser;
    //todo 资源清单
    //private List<UmsResource> resourceList;


    public AdminUserDetails(PipeUser pipeUser) {
        this.pipeUser = pipeUser;
    }

    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        SimpleGrantedAuthority simpleGrantedAuthority = new SimpleGrantedAuthority("ROOT");
        return Arrays.asList(simpleGrantedAuthority);
    }

    @Override
    public String getPassword() {
        return this.pipeUser.getPassword();
    }

    @Override
    public String getUsername() {
        return this.pipeUser.getUserName();
    }

    @Override
    public boolean isAccountNonExpired() {
        return true;
    }

    @Override
    public boolean isAccountNonLocked() {
        return this.pipeUser.getStatus() != 2;
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }

    @Override
    public boolean isEnabled() {
        return this.pipeUser.getStatus() != 0;
    }
}
